package cn.marinda.runnable;

import cn.marinda.entity.ServerInfo;
import cn.marinda.util.ServerUtils;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;

/**
 * 服务器信息可运行
 *
 * @author admin
 * @date 2022/07/08
 */
public class ServerInfoRunnable extends TimerTask {
    private JFrame jFrame;
    private String text;
    /**
     * 服务器信息
     */
    private ServerInfo serverInfo;
    /**
     * 服务器信息可运行
     *
     * @param serverInfo 服务器信息
     */
    public ServerInfoRunnable(ServerInfo serverInfo,JFrame frame){
        this.serverInfo = serverInfo;
        this.jFrame = frame;

        this.text = frame.getTitle();
    }

    @Override
    public void run() {
        loadServerInfo();
    }

    private void loadServerInfo(){
        ServerUtils.loadDefaultArgs();
        serverInfo.setCpuCount(ServerUtils.getCPUCount());
        serverInfo.setCpuRate(ServerUtils.getCPURate());
        serverInfo.setCpuName(ServerUtils.getCPUName());
        serverInfo.setRamRate(ServerUtils.getRamRate());
        serverInfo.setRamCount(ServerUtils.getRamCount());
        serverInfo.setRamSurplus(ServerUtils.getSurplus());
        serverInfo.setRamTotal(ServerUtils.getRamTotal());
        jFrame.setTitle(this.text + " " +  serverInfo.getCpuName() +  " "+ serverInfo.getCpuRate() + " " + serverInfo.getRamSurplus());
    }

}
